package org.walker.iotScheduling.modules.iot.v1.job;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
import org.springframework.stereotype.Component;
import org.walker.iotScheduling.modules.iot.v1.timeTask.TimeStrategy;
import org.walker.iotScheduling.modules.iot.v1.timeTask.impl.FixedRateSchedulingStrategyFiveSeconds;
import org.walker.iotScheduling.modules.iot.v1.timeTask.impl.FixedRateSchedulingStrategyTenSeconds;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CompletableFuture;

/**
 * 没用的东西，V1别看了
 * @author :zhuangguojin
 * @since :2024/12/4 14:08
 */
@Component
public class SchedulerJob {

    @Autowired
    @Qualifier("ThreadPoolSchedulerCommon")
    private ThreadPoolTaskScheduler scheduler;
    @Autowired
    private FixedRateSchedulingStrategyFiveSeconds fiveSeconds;
    @Autowired
    private FixedRateSchedulingStrategyTenSeconds tenSeconds;

    //@PostConstruct 取消V1 根本没用到
    public void manageSchedulerJob() {
        List<TimeStrategy> strategies = new ArrayList<TimeStrategy>();
        strategies.add(fiveSeconds);
        strategies.add(tenSeconds);

        // 注入scheduler执行TimeStrategy.scheduleTask
        strategies.forEach(o -> {
            CompletableFuture.runAsync(o::scheduleTask, scheduler);
        });

    }


}
